package com.five.monkey.feign.es.convert;

import com.five.monkey.feign.es.dao.model.User;
import com.five.monkey.util.TimeUtils;
import com.five.monkey.vo.UserVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.util.Objects;

/**
 * @author 狻猊
 * @date 2022-03-28 20:30:14
 */
public class UserConvert {

    private UserConvert() {}

    public static UserVo esModel2vo(User user) {
        if (Objects.isNull(user)) {
            return null;
        }
        UserVo vo = new UserVo();
        BeanUtils.copyProperties(user, vo);
        return vo;
    }

    public static User vo2esModel(UserVo vo) {
        if (Objects.isNull(vo)) {
            return null;
        }
        User user = new User();
        BeanUtils.copyProperties(vo, user);
        if (StringUtils.isBlank(user.getCreateTime())) {
            user.setCreateTime(TimeUtils.parseDate());
        }
        if (StringUtils.isBlank(user.getUpdateTime())) {
            user.setUpdateTime(TimeUtils.parseDate());
        }
        return user;
    }
}
